using Godot;
using GodotInk;
using System;
using System.Collections.Generic;
using System.Runtime;
using System.Threading;
using System.Timers;

public partial class LoadingAndLogin : SceneBase
{
	// Called when the node enters the scene tree for the first time.
	private float maxProgress = 100;
	private float nowProgress = 0;
	private ProgressBar bar = null;

	private bool isLoadFinish = false;
	public override void _Ready()
	{
		//GD.Print("转字符" + SceneId.LoginScene.ToString() + "  元数据：" + SceneId.LoadingScene);
		//SceneModel.getInstance().currentScene = this.GetTree().CurrentScene;
		this.bar = this.GetNode<ProgressBar>("TextureRect/LoadingBar");
		this.bar.MaxValue = this.maxProgress;

		//SceneManager.getInstance().currentScene = this;

		//加载一些资源
		this.loadConfig();
		this.loadMainScene();
		//ViewManager.getInstance().open("LoadingView");


	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		this.bar.Value = this.nowProgress;
		if (this.nowProgress == 100 && !isLoadFinish)
		{
			isLoadFinish = true;
			ViewManager.getInstance().open("LoginInView");
		}
	}

	//初始化一些配置
	private void loadConfig()
	{
		ViewConfig.init();
		ConfigManager.getInstance().init();

		this.nowProgress = 10;
	}

	private void loadMainScene()
	{
		//var scene = GD.Load<PackedScene>(SceneUtil.getScenePath(SceneId.GameScene));
		//SceneManager.getInstance().nextScene = scene.Instantiate<Node2D>();

		this.nowProgress = 100;
	}

	//加载UI数据
	private void loadingUi()
	{
		/*

		foreach (var v in SceneConfig.sceneDict.Values)
		{
			var path = "res://scene/" + v.SceneName + ".tscn";
			var err = ResourceLoader.LoadThreadedRequest(path);
			GD.PrintErr(err);
			while (true)
			{
				var status = ResourceLoader.LoadThreadedGetStatus(path);
				if (status == ResourceLoader.ThreadLoadStatus.Loaded)
				{
					this.bar.Value = 100;
					var scene = (PackedScene)ResourceLoader.LoadThreadedGet(path);
					SceneModel.getInstance().initView(v.SceneName, scene);
					break;
				}
			}


		}*/


	}

	//加载场景数据
	private void loadingScene()
	{

		/*foreach (var v in SceneConfig.sceneDict.Values)
		{
			var path = "res://scene/" + v.SceneName + ".tscn";
			var err = ResourceLoader.LoadThreadedRequest(path);
			GD.PrintErr(err);
			while (true)
			{
				var status = ResourceLoader.LoadThreadedGetStatus(path);
				if (status == ResourceLoader.ThreadLoadStatus.Loaded)
				{
					this.bar.Value = 100;
					var scene = (PackedScene)ResourceLoader.LoadThreadedGet(path);
					SceneModel.getInstance().initView(v.SceneName, scene);
					break;
				}
			}


		}*/
	}
}



